package boot.config;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: fengshun
 * @Date:2024/8/16 18:44
 * @DESC:
 */
@Component
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        System.out.println("请求的路径：" +requestURI);
        Object token = request.getSession().getAttribute("token");
        System.out.println("token = " + token);
        if (token!=null||requestURI.contains("css")||requestURI.contains("js")||requestURI.contains("images")){
            return true;
        }else {
            response.sendRedirect("/login.html");
        }
        return false;
    }
}

